#include "moveimpl.h"
#include <QDebug>

MoveImpl::MoveImpl(Cell *first, Cell *second)
{
    m_first = first;
    m_second = second;
    m_nextMoves = new std::list<MoveImpl*>;
}

MoveImpl::MoveImpl()
{
    m_nextMoves = new std::list<MoveImpl*>;
}

bool MoveImpl::hasNext()
{
    return m_nextMoves->size() > 0;
}

MoveImpl* MoveImpl::addMove(Cell *start, Cell *stop)
{
    MoveImpl* m = new MoveImpl(start, stop);
    m->previousMove = this;
    m_nextMoves->push_back(m);
    return m;
}

std::list<MoveImpl *> *MoveImpl::getNextMoves()
{
    return m_nextMoves;
}

MoveImpl *MoveImpl::getPreviousMove()
{
    return previousMove;
}

Cell *MoveImpl::getFirst()
{
    return m_first;
}

Cell *MoveImpl::getSecond()
{
    return m_second;
}

bool MoveImpl::isZeroMove()
{
    return m_first == nullptr and m_second == nullptr;
}

void MoveImpl::print()
{
    MoveImpl *m = this;
    while (true){
        if (m == nullptr || m->isZeroMove()){
            break;
        }
        qDebug() << m->getFirst()->getX() << m->getFirst()->getY() << " : " << m->getSecond()->getX() << m->getSecond()->getY();
        m = m->getPreviousMove();
    }
    qDebug() << "";
}

MoveImpl *MoveImpl::ZERO_MOVE()
{
    return new MoveImpl;
}
